<?php
// $connect = mysql_connect('mysql17.000webhost.com','a4117838_simple','123simple');
$connect = mysql_connect('localhost','root','');
if (!$connect){
  die('Could not connect: ' . mysql_error($connect));
}
// mysql_select_db('a4117838_simple',$connect);
mysql_select_db('mydatabase',$connect);
$dataoption   = $_POST['dataoption'];


if($dataoption == "tabledata"){
	$tablename 	= $_POST['tablename'];
	$tableresult= mysql_query("SELECT id from tablelist where tablename = '$tablename'");
	while($tablerow = mysql_fetch_array($tableresult)){
		$tableid = $tablerow[0];
	} 	
	$result  = mysql_query("SELECT * from question where tablename= '$tableid' ");
        while ($row = mysql_fetch_array($result)) {
		$questionid 	= $row[0];
		$question 	= $row[1];
		$answer_option	= $row[2];
		
		echo '<p><label>Selecteer uw vraag</label><input data-qid="'.$questionid.'" id="q1" name="q1" class="q1" type="text" size="23" maxlength="90" placeholder="Enter question" value="'.$question.'" /></p>';

		echo '<p><label>Choose type:</label><select id="answer" class="answer" name="answer" disabled>';
		if($answer_option == "dropdown"){
                    echo '<option value="0">Make your choice</option>';
                    echo '<option value="box">Box</option>';
                    echo '<option value="email">Email</option>';
                    echo '<option value="dropdown" selected="selected">Dropdown</option>';
                    echo '</select></p>';
                    $answer_result  = mysql_query("SELECT * from subquestion where question_id = '$questionid'");
                    while($subquestionrow = mysql_fetch_array($answer_result)){
                        $subquestionid      = $subquestionrow[0];
                        $subquestion        = $subquestionrow[2];
                        $subquestionoption  = $subquestionrow[3];
                        
                        $subanswerquery = mysql_query("SELECT * from subanswer where sub_question_id = '$subquestionid' ");
                        
                        while ($subanswerrow = mysql_fetch_array($subanswerquery)) {
                            echo '<p><label>Selecteer uw vraag</label>';
                            echo '<input id="q1" name="q1" class="q1" type="text" size="23" maxlength="90" placeholder="Enter question" value="'.$subquestion.'">';
                            echo '</p>';
                            echo '<p><div id="msg"><label>Voer antwoord te worden gegeven</label>';
                            echo '<textarea name="msg1" id="msg1" cols="5" rows="5">'.$subanswerrow[2].'</textarea></div><p>';                        
                        }
                        
                    }
		}
		else{
                    if($answer_option == "box"){
                        echo '<option value="0">Make your choice</option>';
                        echo '<option value="box" selected="selected">Box</option>';
                        echo '<option value="email">Email</option>';
                        echo '<option value="dropdown">Dropdown</option>';
                    }
                    else if($answer_option == "email"){
                        echo '<option value="0">Make your choice</option>';
                        echo '<option value="box">Box</option>';
                        echo '<option value="email" selected="selected">Email</option>';
                        echo '<option value="dropdown">Dropdown</option>';
                    }
                    echo '</select></p>';
                    $answer_result    = mysql_query("SELECT * from answer where question_id = '$questionid'");
                    while ($answerrow = mysql_fetch_array($answer_result)) {
                        echo '<p><label>Selecteer uw vraag</label>';
                        echo '<input id="q1" name="q1" class="q1" type="text" size="23" maxlength="90" placeholder="Enter question" value="'.$question.'">';
                        echo '</p>';
                        echo '<p><div id="msg"><label>Voer antwoord te worden gegeven</label>';
                        echo '<textarea name="msg1" id="msg1" cols="5" rows="5">'.$answerrow[1].'</textarea></div><p>';
                    }
		}
	}
}
?>